﻿
namespace VS.Web.Services
{
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.ServiceModel.DomainServices.Hosting;
    using System.ServiceModel.DomainServices.Server;
    using VS.Web.Model;
    using System.Web.Configuration;
    using System.IO;
    using System.Web;
    
    
    // TODO: Create methods containing your application logic.
    [EnableClientAccess()]
    public class FileService : DomainService
    {
        public IQueryable<WebFile> GetFiles()
        {
            string path = WebConfigurationManager.AppSettings["UploadDir"];
            List<WebFile> webFiles = new List<WebFile>();
            if (string.IsNullOrEmpty(path)) return webFiles.AsQueryable();
            DirectoryInfo di = new DirectoryInfo(HttpContext.Current.Server.MapPath(path));

            foreach (FileInfo file in di.GetFiles())
                webFiles.Add(new WebFile { FileName = file.Name });

            return webFiles.AsQueryable();
        }

        public void InsertFile(WebFile file)
        {
            FileHandler.HandleFile(file);
        }
    }
}


